package vmcs.simulationsystem;

import java.awt.Button;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import vmcs.common.VMCSException;
import vmcs.customer.CoinReceiver;

public class CoinInputListener implements ActionListener{

	private CoinReceiver coinReceiver;
	
	public CoinInputListener(CoinReceiver coinReceiver) {
	    this.coinReceiver = coinReceiver;
	  }
	
	@Override
	public void actionPerformed(ActionEvent e) {
		String cmd;
        double weight;
        Button btn;

        btn = (Button) e.getSource();
        cmd = btn.getActionCommand();
        weight = Double.parseDouble(cmd);
        
        try {
			coinReceiver.receiveCoin(weight);
		} catch (VMCSException e1) {
			e1.printStackTrace();
		}
		
	}

}
